
$(document).ready(function(){
    //$('#showcase-list').cxScroll({ direction: "left", step: 3, auto: false, plus: false, minus: false });
    //$('#news-list').cxScroll({ direction: "left", step: 4, auto: false, plus: false, minus: false });
    var H5VideoPlayer = $("#video-player").find("video")[0];

    if (H5VideoPlayer) {
        var IsPlayerPlay = false;
        H5VideoPlayer.addEventListener("play", function () {
            IsPlayerPlay = true;
            $("#video-player").find("img").hide();
        });
        H5VideoPlayer.addEventListener("pause", function () {
            IsPlayerPlay = false;
            $("#video-player").find("img").show();
        });
        H5VideoPlayer.addEventListener("ended", function () {
            IsPlayerPlay = false;
            $("#video-player").find("img").show();
        });
    }

    $('#quick-step-btn').on('click', function () {
        var plan = $('#quick-plan').find('li.active').text();
        var style1 = $('#quick-style').find('li.active');
        var style = "";
        $.each(style1, function (index, value) {
            style += $(value).text() + ",";
        });
        var place = $('#quick-place').find('li.active').text();
        var price = $('#quick-price').find('li.active').text();
        var name = $('#quick-name').val();
        var tel = $('#quick-phone').val();

        if (name == "") {
            alert("请留下您的姓名，以便我们称呼您！");
            return;
        }
        if (tel == "") {
            alert("请留下您的手机号码，以便我们联系您！");
            return;
        }
        $.ajax({
            type: 'post',
            url:'/app/sign.php',
            dataType:'json',
            data:
            {
                Style: style,
                Location: place,
                Plan: plan,
                PriceType: price,
                Tel: tel,
                UserName: name
            }
            ,success: function(data)
            {
                $('#name').val('');
                $('#phone').val('');
                if(data.code==1)
                {
                    alert('您已成功预约您的婚纱照拍摄, 请等待客服人员与您联系！');
                    $('#quick-name').val("");
                    $('#quick-phone').val("");
                }
                else{
                    alert("存在重复信息");
                    $('#quick-name').val("");
                    $('#quick-phone').val("");
                }

            }
            ,error:function(XMLHttpRequest ,textStatus,errorThrown){
                alert("提交成功，我们将尽快与您联系");
            }
        });
        //mi.apiService.callPost('/app/sign.php', { Style: style, Location: place, Plan: plan, PriceType: price, Tel: tel, UserName: name }, function (data) {
        //    if (data.code == 1) {
        //        alert('您已成功预约您的婚纱照拍摄, 请等待客服人员与您联系！');
        //        $('#quick-name').val("");
        //        $('#quick-phone').val("");
        //    } else {
        //        alert(data.msg);
        //        $('#quick-name').val("");
        //        $('#quick-phone').val("");
        //    }
        //}, function (data) {
        //    alert(data.msg);
        //    $('#quick-name').val("");
        //    $('#quick-phone').val("");
        //});
    });

    $('.quick-step').on('click', 'li.itt', function () {
        $(this).siblings().removeClass('active');
        $(this).addClass('active');
    });
    $('#quick-style').on('click', 'li', function () {
        //if ($(this).hasClass('active')) {
        //    $(this).removeClass('active');
        //} else {
        //    $(this).addClass('active');
        //}
        $(this).toggleClass('active');
    });
    $('.quick-btn-next').on('click', function () {
        var $item = $(this).parent().find("ul");
        $item.scrollTop($item.scrollTop() + 61);
    });

    //拍摄风格
    var control_li = $('#sample-control').find('li');

    var sample_slider = $('#sample-banner').bxSlider({
        controls: false,
        autoControls: false,
        autoHover: true,
        easing: 'linear',
        pager: false,
        onSlideBefore: function ($slideElement, oldIndex, newIndex) {
            control_li.eq(oldIndex).removeClass('active');
            control_li.eq(newIndex).addClass('active');
        },
        onSlideAfter: function ($slideElement, oldIndex, newIndex) {
            control_li.removeClass('active');
            control_li.eq(newIndex).addClass('active');
        },
        onSliderLoad: function (currentIndex) {
            control_li.eq(currentIndex).addClass('active');
            this.goToSlide(currentIndex);
        }

    });

    $.each(control_li, function (index, value) {
        $(value).on('click', function () {
            control_li.eq(index).addClass('active');
            sample_slider.goToSlide(index);
        });
    });


    //拍摄影像

    var video_controle = $('#video-control').bxSlider({
        autoControls: false,
        easing: 'linear',
        pager: false,
        nextSelector: '.video-next',
        prevSelector: '.video-prev',
        nextText: '',
        prevText: '',
        minSlides: 3,
        maxSlides: 3,
        slideWidth: 483.3,
        slideMargin: 0
    });

    //    新闻动态

    var news_li = $('#news-l').bxSlider({
        controls: true,
        autoControls: false,
        autoHover: true,
        easing: 'linear',
        pager: false,
        nextSelector: '.news-next',
        prevSelector: '.news-prev',
        nextText: '',
        prevText: '',
        minSlides: 3,
        maxSlides: 3,
        slideWidth: 442,
        slideMargin: 55
    });

    $("#video-player").on("click", function () {
        if (H5VideoPlayer) {
            if ($(H5VideoPlayer).attr("src")) {
                if (IsPlayerPlay) {
                    H5VideoPlayer.pause();
                }
                else {
                    H5VideoPlayer.play();
                }
            }
            else {
                $(H5VideoPlayer).attr("src", $("#video-control li").eq(0).attr("link"));
                H5VideoPlayer.play();
            }
        }
    });

    $("#video-control").on('click', 'li', function () {
        if (H5VideoPlayer) {
            $("#video-control li").find(".post-icon").show();
            H5VideoPlayer.pause();
            var src = $(this).attr("link");
            $(H5VideoPlayer).attr("src", src);
            H5VideoPlayer.play();
            $(this).find(".post-icon").hide();
            $("#video-player").find("img").hide();
        }
    });
});
